/**
 * 获取模板消息
 * @param ids 模板id
 * @returns {Promise<unknown>}
 */
export const subscribeMessage = (ids = []) => {
  return new Promise(resolve => {
    uni.requestSubscribeMessage({
      tmplIds: ids,
      success: (res) => {
        let reject = ids.filter(val => {
          return res[val] === 'reject'
        })
      
        if (reject.length) {
          uni.showModal({
            title: '请开启消息通知',
            content: '请订阅消息通知,否则各种精选信息无法通知到你!',
            confirmText: '立即开启',
            success: (result) => {
              if (result.confirm) {
                subscribeMessage(reject);
              } else {
                resolve();
              }
            }
          })
        } else resolve();
      },
      fail: (err) => {
        console.log(err)
      }
    })
  })
}

export default subscribeMessage
